var express = require('express');
var router = express.Router();
var identityKey = 'skey';

const Util = require('../note/Util');
const db = require('../note/db');

// 定义当前路由主页
router.get('/', function(req, res) {

   var uid = req.session.loginUserId;
   try {
     db.user.find({
       where:{
         id:uid,
         status:0,
       }
     }).then(ret=>{
       console.log(ret);
       var datas = ret;
       try {
         db.notes.findAndCountAll({
           where:{
             uid:uid,
             status:0,
           }
         }).then(ret=>{
          //  console.log('笔记数量',ret);
           datas.counts = ret.count;
           res.render('me', { title: 'note', data:{msg:'用户信息',code:520,datas:datas},util:Util });
         })
       } catch (e) {
         res.render('error', { title: '获取用户信息出错', data:{msg:'获取用户信息出错',code:110} });
         console.log('获取用户信息出错',e);
       }

     })

   } catch (e) {
     res.render('error', { title: '获取用户信息出错', data:{msg:'获取用户信息出错',code:110} });
     console.log('获取用户信息出错',e);
   }
});

module.exports = router;
